extends Node3D
#ps： 这个脚本其实也可以挂在Entities的子节点中，作为“移动的旋转轴”

#控制范围（广度、厚度，以及方向）
@export_enum("x+:0","x-:1","y+:2","y-:3","z+:4","z-:5") var rotate_axis:int:
	set(value):
		rotate_axis = value
		match value:
			0:
				axis = Vector3i(1,0,0)
			1:
				axis = Vector3i(-1,0,0)
			2:
				axis = Vector3i(0,1,0)
			3:
				axis = Vector3i(0,-1,0)
			4:
				axis = Vector3i(0,0,1)
			5:
				axis = Vector3i(0,0,-1)
var axis:Vector3i = Vector3i(1,0,0) # 由于标准使用只能用特定值，所以用上面这个变量辅助设定了
@export var hight:int = 1 # postive axis
@export var expand:int = 0

# 子节点加载出来时父节点还没出来，所以需要onready来延迟一下
@onready var level_root = get_owner()


func get_rotation_box(center:Vector3,axis:Vector3i,hight:int,expand:int)->AABB:
	var start:Vector3
	var size:Vector3
	match axis :
		Vector3i(1,0,0), Vector3i(-1,0,0):
			size = Vector3(hight,2*expand+1,2*expand+1)
			start = center+Vector3(0,-expand,-expand)
		Vector3i(0,1,0), Vector3i(0,-1,0):
			size = Vector3(2*expand+1,hight,2*expand+1)
			start = center+Vector3(-expand,0,-expand)
		Vector3i(0,0,1), Vector3i(0,0,-1):
			size = Vector3(2*expand+1,2*expand+1,hight)
			start = center+Vector3(-expand,-expand,0)
			
	return AABB(start, size)

func rotate_part():
	#右手螺旋法则式旋转
	#var center:Vector3 = global_transform.origin - gridmap.global_transform.origin
	level_root.rotate_level(get_rotation_box(position,axis,hight,expand),axis)
	# gridmap中的方块操作函数基本上都是相对位置的样子？
	
	
